package com.reach.redis.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import com.reach.redis.aspect.CacheAspect;
import com.reach.redis.bo.CacheConfig;
import com.reach.redis.factory.RedisCache;
import com.reach.redis.factory.RedisEnableCache;
import com.reach.redis.interceptor.QueryCacheInterceptor;
import com.reach.redis.manager.ManagerCache;
import com.reach.redis.manager.SpringContextUtil;

@Configuration
public class BeanManager {

	@Bean
	public  SpringContextUtil springContextUtil() {
		return new SpringContextUtil();
	}
	
	@DependsOn("springContextUtil")
	@Bean("cacheInterceptor")
	public QueryCacheInterceptor cacheInterceptor() {
		return new QueryCacheInterceptor();
	}
	
	@DependsOn("cacheInterceptor")
	@Bean("redisEnableCache")
	public RedisEnableCache redisEnableCache() {
		return new RedisEnableCache();
	}

	@DependsOn("redisEnableCache")
	@Bean("redisCache")
	public RedisCache redisCache() {
		return new RedisCache();
	}
	
	/*@DependsOn("redisCache")
	@Bean("beanNameAutoProxyCreator")
	public BeanNameAutoProxyCreator beanNameAutoProxyCreator() {
		BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator();
		beanNameAutoProxyCreator.setInterceptorNames("cacheInterceptor");
		beanNameAutoProxyCreator.setBeanNames("baiduGeocoderService");
		return beanNameAutoProxyCreator;
	}*/
	
	@DependsOn("redisCache")
	@Bean("cacheAspect")
	public CacheAspect  cacheAspect() {
		return new CacheAspect();
	}
	
	
	private String[] getBeanNames() {
		List<String> beanList = new ArrayList<>();
		for(Map.Entry<String, CacheConfig>  cache : ManagerCache.queryCacheMap.entrySet()) {
			beanList.add(cache.getValue().getBeanName());
		}
		return null;
	}
	

}
